package com.wxy.config;

import io.jsonwebtoken.Jwt;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 47868
 */
public class jwtConfig {
    private static final String JWTTOKEN="123456Mszlu!@#$$";
    private static final long TIME= 24L *60*60*60*1000;
    public static String getToken(int id) {
        Map<String,Object> claims= new HashMap<>(5);
        claims.put("userId",id);
        JwtBuilder jwtBuilder= Jwts.builder()
                .signWith(SignatureAlgorithm.HS256,JWTTOKEN)
                .setClaims(claims)
                .setIssuedAt(new Date())
                .setExpiration(new Date(System.currentTimeMillis()+TIME));
        return jwtBuilder.compact();
    }
    public static Map<String,Object> checkToken(String token){
        Jwt parse=Jwts.parser().setSigningKey(JWTTOKEN).parse(token);
        return (Map<String, Object>) parse.getBody();
    }
}